package com.myself.ssoserver.repository

import com.myself.common.repository.BaseRepository
import com.myself.ssoserver.entity.*
import com.myself.ssoserver.entity.LoginHistories.loginHistories
import com.myself.ssoserver.entity.Users.users
import org.ktorm.database.Database
import org.ktorm.dsl.and
import org.ktorm.dsl.eq
import org.ktorm.entity.filter
import org.ktorm.entity.find
import org.springframework.stereotype.Repository

@Repository
open class UserRepository(
    private val dataBase: Database
) : BaseRepository<User, Users>(dataBase.users) {
    open fun findByUsername(username: String): User? {
        return dataBase.users
            .find { it.username eq username }
    }

}

@Repository
open class LoginHistoryRepository(
    private val dataBase: Database,
) : BaseRepository<LoginHistory, LoginHistories>(
    dataBase.loginHistories
)